import request from '@/utils/request'
/** 菜单操作 */
export function fetchMenuList(query) {
  return request({
    url: '/sys/menu/list',
    method: 'get',
    params: query
  })
}

export function updateMenu(menu) {
  let url = '/sys/menu/add'
  if (menu.menuId) {
    url = '/sys/menu/update'
  }
  return request({
    url: url,
    method: 'post',
    params: menu
  })
}
export function findByMenuId(menuId) {
  const url = '/sys/menu/' + menuId
  return request({
    url: url,
    method: 'get'
  })
}
export function deleteByMenuId(menuId) {
  const url = '/sys/menu/delete/' + menuId
  return request({
    url: url,
    method: 'post'
  })
}
/** 部门操作 */
export function fetchDeptList(query) {
  return request({
    url: '/sys/dept/list',
    method: 'get',
    params: query
  })
}

export function updateDept(dept) {
  let url = '/sys/dept/add'
  if (dept.deptId) {
    url = '/sys/dept/update'
  }
  return request({
    url: url,
    method: 'post',
    params: dept
  })
}
export function findByDeptId(deptId) {
  const url = '/sys/dept/' + deptId
  return request({
    url: url,
    method: 'get'
  })
}
export function deleteByDeptId(deptId) {
  const url = '/sys/dept/delete/' + deptId
  return request({
    url: url,
    method: 'post'
  })
}
/** 角色操作 */
export function fetchRoleList(query) {
  return request({
    url: '/sys/role/list',
    method: 'get',
    params: query
  })
}

export function updateRole(role) {
  let url = '/sys/role/add'
  if (role.roleId) {
    url = '/sys/role/update'
  }
  return request({
    url: url,
    method: 'post',
    params: role
  })
}
export function findByRoleId(roleId) {
  const url = '/sys/role/' + roleId
  return request({
    url: url,
    method: 'get'
  })
}
export function deleteByRoleId(roleId) {
  const url = '/sys/role/delete/' + roleId
  return request({
    url: url,
    method: 'post'
  })
}
/** 人员操作 */
export function fetchUserList(query) {
  return request({
    url: '/sys/user/page',
    method: 'get',
    params: query
  })
}

export function updateUser(user) {
  let url = '/sys/user/add'
  if (user.userId) {
    url = '/sys/user/update'
  }
  return request({
    url: url,
    method: 'post',
    params: user
  })
}
export function findByUserId(userId) {
  const url = '/sys/user/' + userId
  return request({
    url: url,
    method: 'get'
  })
}
export function deleteByUserId(userId) {
  const url = '/sys/user/delete/' + userId
  return request({
    url: url,
    method: 'post'
  })
}
